home *** CD-ROM | disk | FTP | other *** search
- bool
- do_close(stab,explicit)
- STAB *stab;
- bool explicit;
- {
- bool retval = FALSE;
- register STIO *stio;
- int status;
-
- if (!stab)
- stab = argvstab;
- if (!stab) {
- errno = EBADF;
- return FALSE;
- }
- stio = stab_io(stab);
- if (!stio) { /* never opened */
- if (dowarn && explicit)
- warn("Close on unopened file <%s>",stab_ename(stab));
- return FALSE;
- }
- if (stio->ifp) {
- if (stio->type == '|') {
- status = mypclose(stio->ifp);
- retval = (status == 0);
- statusvalue = (unsigned short)status & 0xffff;
- }
- else if (stio->type == '-')
- retval = TRUE;
- else {
- if (stio->ofp && stio->ofp != stio->ifp) { /* a socket */
- retval = (fclose(stio->ofp) != EOF);
- fclose(stio->ifp); /* clear stdio, fd already closed */
- }
- else
- retval = (fclose(stio->ifp) != EOF);
- }
- stio->ofp = stio->ifp = Nullfp;
- }
- if (explicit)
- stio->lines = 0;
- stio->type = ' ';
- return retval;
- }
-
-